<template>
  <!-- 维护作业-集汇汇缴件补交页面 -->
  <div class="fillcontain">
    <el-form :model="searchParams" :rules="searchRules" ref="ruleForm" label-width="100px" class="search_container">
      <el-row>
        <el-col :span="6">
          <el-form-item label="操作人ID" prop="crtuser">
            <el-input clearable v-model="searchParams.crtuser" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="受理号码" prop="applnum">
            <el-input clearable v-model="searchParams.applnum" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="收款凭证号码" prop="wnotnum">
            <el-input clearable v-model="searchParams.wnotnum" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </el-form>
    <div class="contain">
      <el-row class="bgfff pb15">
        <el-col :span="24" class="pt5">
          <el-button type="danger" plain @click="addClick">新增</el-button>
        </el-col>
      </el-row>
      <!-- 查询结果 -->
      <div class="table_container">
        <el-table
            v-loading="loading"
            :data="tableData"
            highlight-current-row
            header-cell-class-name="table-header-class"
            style="width:100%">
          <el-table-column
              min-width="120"
              property="chdrnum"
              label="保单号码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="applnum"
              label="受理号码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="wnotnum"
              label="发票号码"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="crtuser"
              label="操作人ID"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="dtecrt"
              label="建立日期"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              min-width="120"
              property="crttime"
              label="建立时间"
              align='center'
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              fixed="right"
              label="操作"
              align='center'>
            <template slot-scope="scope">
              <!-- <el-button type="text" size="small" @click="deleteInfo(scope.row)">删除</el-button> -->
              <span class="operationIcon" @click="deleteInfo(scope.row)">
                            <el-tooltip class="item" effect="light" content="删除" placement="top">
                                <i class="el-icon-delete"></i>
                            </el-tooltip>
                        </span>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <el-pagination
                  background
                  v-if='paginations.total > 0'
                  :page-sizes="paginations.pageSizes"
                  :page-size="paginations.pageSize"
                  :layout="paginations.layout"
                  :total="paginations.total"
                  :current-page='paginations.pageIndex'
                  @current-change='handleCurrentChange'
                  @size-change='handleSizeChange'>
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 弹框 增加-->
    <el-dialog
        v-if="showDialog"
        title="增加集汇汇缴件补交"
        :visible.sync="showDialog"
        width="50%"
        center>
      <el-form :model="form" ref="formRules" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12" class="common-box">
            <el-form-item label="保单号码" prop="chdrnum">
              <el-input clearable v-model="form.chdrnum" maxlength="8" placeholder="请输入"></el-input>
            </el-form-item>
            <!-- <el-col :span="8" class="common-lab">
                 <label class="labelName">保单号码</label>
            </el-col>
             <el-col :span="16">
                 <el-input clearable v-model="searchParams.chdrnum" placeholder="请输入"></el-input>
             </el-col> -->
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="受理号码" prop="applnum">
              <el-input disabled v-model="form.applnum" readonly maxLength="7" placeholder="请输入"></el-input>
            </el-form-item>
            <!-- <el-col :span="8" class="common-lab">
                 <label class="labelName">受理号码</label>
            </el-col>
             <el-col :span="16">
                <el-input v-model="searchParams.applnum" placeholder="请输入"></el-input>
             </el-col> -->
          </el-col>
          <el-col :span="12" class="common-box">
            <el-form-item label="收款凭证号码" prop="wnotnum">
              <el-input clearable v-model="form.wnotnum" maxLength="9" placeholder="请输入"></el-input>
            </el-form-item>
            <!-- <el-col :span="8" class="common-lab">
                 <label class="labelName">收款凭证号码</label>
            </el-col>
             <el-col :span="16">
                 <el-input placeholder="请输入" ></el-input>
             </el-col> -->
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="addInfo" class="Defaultbutton">保 存</el-button>
                <el-button @click="showDialog = false">返 回</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script>
  import {mapGetters} from 'vuex'
  import constant from '@/utils/constant';
  import * as api from '@/api/setting/maintain/collectionPayment.js'
  import validRules from "../../../utils/validRules";

  export default {
    data() {
      var checkChdrnum = (rule, value, callback) => {
        var that = this;
        let CHNReg = /[\u4e00-\u9fa5]/;//汉字的正则表达式
        if (value.match(CHNReg)) {
          callback(new Error('保单号码不能为汉字'));
        } else {
          if (value.length < 8) {
            callback(new Error('注意,保单号码为必要性栏位不可空白或长度不对, 请输入'));
          } else {
            let params = {
              chdrnum: value
            }
            api.getApplnumByChdrnum(params).then(res => {
              console.log(res)
              // this.$store.dispatch('loading/CHANGE_LOADING',false)
              if (res.resultCode == constant.SUCCESS && res.data) {
                that.form.applnum = res.data;
                callback();
              } else {
                callback(new Error(res.resultMsg));
              }
            }).catch(err => {
              console.log(err)
              callback(new Error("系统错误"));
            })
          }
        }
      };
      var checkWnotnum = (rule, value, callback) => {
        let CHNReg = /[\u4e00-\u9fa5]/;//汉字的正则表达式
        if (value.match(CHNReg)) {
          callback(new Error('收款凭证号码不能为汉字'));
        } else {
          if (value.length < 9) {
            callback(new Error('注意,收款凭证号码为必要性栏位不可空白或长度不对, 请输入'));
          } else {
            let params = {
              wnotnum: value
            }
            api.getWnotnumCountByWnotnum(params).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                if (res.data > 0) {
                  this.form.wnotnum = "";
                  callback(new Error('注意, 收款凭证号码在EUIS处理状态已经使用, 请重新输入'));
                } else {
                  callback();
                }
              } else {
                callback(new Error(res.resultMsg));
              }
            }).catch(err => {
              callback(new Error("系统错误"));
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        }
      };
      return {
        valueDate: '',
        showDialog: false,//默认隐藏 '增加'弹框
        // 查询条件
        rules: {
          chdrnum: [
            {required: true, message: '注意,保单号码为必要性栏位不可空白或长度不对, 请输入', trigger: 'blur'},
            {validator: checkChdrnum, trigger: 'blur'}
          ],
          applnum: [
            {required: true, message: '注意,受理号码为必要性栏位不可空白或长度不对, 请输入', trigger: 'blur'},

          ],
          wnotnum: [
            {required: true, message: '注意,收款凭证号码为必要性栏位不可空白或长度不对, 请输入', trigger: 'blur'},
            {validator: checkWnotnum, trigger: 'blur'}
          ],
        },
        searchParams: {
          crtuser: '',
          applnum: '',
          wnotnum: '',
        },
        searchRules: {
          crtuser: [
            {validator: validRules.isEnglishOrNumber, message: '请正确输入操作人ID！', trigger: 'blur'}
          ],
          applnum: [
            {validator: validRules.isEnglishOrNumber, message: '请正确输入受理号！', trigger: 'blur'}
          ],
          wnotnum: [
            {validator: validRules.isEnglishOrNumber, message: '请正确输入收款凭证号码！', trigger: 'blur'}
          ]
        },
        tableData: [],
        loading: false,

        form: {
          chdrnum: '',
          applnum: '',
          wnotnum: '',
        },
        option: '',
        options: [
          {value: '1', label: '测试1'},
          {value: '2', label: '测试2'}
        ],

        //需要给分页组件传的信息
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
        },
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        }
      }
    },
    created() {
//          this.getList();
    },
    mounted() {
      // this.getList();
    },
    methods: {
      // checkChdrnum(str) {

      // },
      // checkWnotnum(str) {

      // },
      addClick() {
        this.form = {
          chdrnum: '',
          applnum: '',
          wnotnum: '',
        }
        this.showDialog = true;
      },

      // 查询列表
      getList() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.paginations.total = 0;
            this.tableData = [];
            let para = {
              "crtuser": this.searchParams.crtuser,
              "wnotnum": this.searchParams.wnotnum,
              "applnum": this.searchParams.applnum,
              "pageSize": this.paginations.pageSize,
              "pageNumber": this.paginations.pageIndex,
            }

            this.$store.dispatch('loading/CHANGE_LOADING', true)

            api.queryList(para).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                if (res.data && res.data.list.length) {
                  this.paginations.total = res.data.total;
                  this.tableData = res.data.list;
                } else {
                  this.$message({
                    message: '无符合条件任务！',
                    type: 'error'
                  });
                }
              }
            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        });
      },

      addInfo() {
        this.$refs['formRules'].validate((valid) => {
          if (valid) {
            api.addData(this.form).then(res => {
              this.$store.dispatch('loading/CHANGE_LOADING', false)
              if (res.resultCode == constant.SUCCESS) {
                this.showDialog = false;
                this.$message.success(res.resultMsg);
                this.searchParams.wnotnum = this.form.wnotnum;
                this.searchParams.applnum = this.form.applnum;
                this.subGetList();
              } else {
                this.$message.error(res.resultMsg);
              }
            }).catch(err => {
              this.$store.dispatch('loading/CHANGE_LOADING', false);
            })
          }
        })

      },

      deleteInfo(row) {
        debugger
        console.log(row)
        this.$confirm('确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params = {
            applnum: row.applnum,
            wnotnum: row.wnotnum,
          }
          api.deleteData(params).then(res => {
            this.$store.dispatch('loading/CHANGE_LOADING', false)
            if (res.resultCode == constant.SUCCESS) {
              this.$message.success(res.resultMsg);
              this.subGetList();
            } else {
              this.$message.error(res.resultMsg);
            }
          }).catch(err => {
            this.$store.dispatch('loading/CHANGE_LOADING', false);
          })
        }).catch(() => {

        });
      },

      // 每页多少条切换
      handleSizeChange(pageSize) {
        this.paginations.pageSize = pageSize;
        this.getList();
      },
      // 上下分页
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.getList();
      },
      // 根据条件查询列表
      subGetList() {
        this.paginations.pageIndex = 1;
        this.getList();
      },
      // 清除查询条件
      resetSearch() {
        this.searchParams.crtuser = '';
        this.searchParams.applnum = '';
        this.searchParams.wnotnum = '';
      }
    },
    computed: {
      ...mapGetters(['tags']),
      reload() {
        return this.$store.state.loading.reload;
      }
    },
    activated() {
      if (this.reload) {
        this.$store.dispatch('loading/CHNAGE_RELOAD', false)
        Object.assign(this.$data, this.$options.data());
      }
    }
  }
</script>

<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }

  .operationIcon {
    // padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 0 3px #f9f9f9;
  }

  .search_container {
    padding: 20px 20px 0 20px;
    //    border-top: 1px solid #e1e1e1;
  }

  .common-box {
    padding-bottom: 15px;
  }

  .common-lab {
    line-height: normal !important;
    text-align: right;

    .labelName {
      text-align: right;
    }
  }
</style>



